<template>
  <div class="login-container">
    <form>
      <div class="form-group">
        <label for="exampleInputEmail1">账户</label>
        <input type="text" class="form-control" id="username" v-model.trim="username" />
      </div>
      <div class="form-group">
        <label for="exampleInputPassword1">密码</label>
        <input type="password" class="form-control" id="psw" v-model.trim="password" />
      </div>
      <button type="button" class="btn btn-primary btn-mar" @click="onLoginClick">登录</button>
      <button type="button" class="btn btn-danger">取消</button>
    </form>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      username: 'admin',
      password: '123456'
    }
  },
  methods: {
    onLoginClick() {
      if (this.username === 'admin' && this.password === '123456') {
        this.$router.push('/home')
        return localStorage.setItem('token', 'Bearer xxx')
      } else {
        localStorage.removeItem('token')
      }
    }
  }
}
</script>

<style lang="less" scoped>
.login-container {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}
form {
  padding: 30px;
  width: 500px;
  text-align: center;
  background-color: #fff;
}
.btn-mar {
  margin-right: 20px;
}
</style>